class signal_coms:
    def __init__(self,signal_keys=[]):
        self.signal_keys=signal_keys
        self.pre_viewpoint=None
        self.pre_viewpoint_n=0
        self.pre_b=None
    def onbar(self,b,timekey=None):
        rst=None
        for i in self.signal_keys:
            if b[i]==-2:
                self.pre_viewpoint = "sell"
                self.pre_viewpoint_n=0
                rst=self.pre_viewpoint
            elif b[i]==2:
                self.pre_viewpoint = "buy"
                self.pre_viewpoint_n=0
                rst = self.pre_viewpoint
        if self.pre_viewpoint_n==1:
            if self.pre_viewpoint=="sell":
                if self.pre_b["close"]<b["close"]:
                    self.pre_viewpoint = "buy"
                    self.pre_viewpoint_n = 0
                    rst = self.pre_viewpoint
            elif self.pre_viewpoint=="buy":
                if self.pre_b["close"]>b["close"]:
                    self.pre_viewpoint = "sell"
                    self.pre_viewpoint_n = 0
                    rst = self.pre_viewpoint
        if self.pre_viewpoint:
            self.pre_viewpoint_n=self.pre_viewpoint_n+1
        self.pre_b=b
        return rst